<template>
    <div>
        <h3>排房增加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房型</td>
                    <td>
                        <select v-model="info.houseTypeId" @change="selecthouseno">
                            <option value="">请选择</option>
                            <option v-for="item in data1.list" :value="item.houseTypeId">{{ item.houseTypeName }}
                            </option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">房号</td>
                    <td>
                        <select v-model="info.houseNoId">
                            <option value="">请选择</option>
                            <option v-for="item in data2.list" :value="item.houseNoId">{{ item.houseNoName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">姓名</td>
                    <td>
                        <input type="text" v-model="info.userName">
                    </td>
                </tr>
                <tr>
                    <td align="right">手机号</td>
                    <td>
                        <input type="text" v-model="info.tel" maxlength="11">
                    </td>
                </tr>
                <tr>
                    <td align="right">身份证</td>
                    <td>
                        <input type="text" v-model="info.card" maxlength="18">
                    </td>
                </tr>

                <tr>
                    <td align="right">入住时间</td>
                    <td>
                        <input type="date" v-model="info.inTime">
                    </td>
                </tr>
                <tr>
                    <td align="right">离店时间</td>
                    <td>
                        <input type="date" v-model="info.outTime">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="增加" class="btn btn-success" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, registerRuntimeCompiler } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let info = reactive({
    "tel": "",
    "card": "",
    "userName": "",
    "houseTypeId": '',
    "houseNoId": '',
    "inTime": "",
    "outTime": ""
})
onMounted(() => {
    Showhousetype();
    //Showhouseno();//房号什么时候加载 选择房型是加载
})

//增加排房
const add = () => {
    //1.判断有效性
    //2.发送请求
    axios({
        url: '/api/HouseType/AddHouseRow',
        method: 'post',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data > 0) {
                alert('添加成功')
            }
            else {
                alert('添加失败')
                return
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
//选择房型时显示房号
const selecthouseno = () => {
    type2.houseTypeId = info.houseTypeId
    Showhouseno();
}
//获取房型的参数
let type: any = reactive({
    pageindex: 1,
    pagesize: 20,
    housetypename: '',
    area1: '',
    area2: ''
})
//返回的房型数据
let data1: any = reactive({
    listcount: '',
    pagecount: '',
    list: []
})
const Showhousetype = () => {
    axios({
        url: '/api/HouseType/GetHouseTypeList',
        method: 'get',
        params: type
    })
        .then((res) => {
            console.log(res);
            Object.assign(data1, res.data)
        })
        .catch((err) => {
            console.log(err);

        })
}
//获取房号列表,后端
let data2: any = reactive({
    listcount: '',
    pagecount: '',
    list: '',
})
let type2: any = reactive({
    pageindex: 1,
    pagesize: 20,
    housenoname: '',
    houseTypeId: '',
})
const Showhouseno = () => {
    axios({
        url: '/api/HouseType/GetHouseNoList',
        method: 'get',
        params: type2
    })
        .then((res) => {
            console.log(res);
            Object.assign(data2, res.data)
        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>